package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class LoginDateBase {
    private String dbdriver="com.mysql.jdbc.Driver";
    private String dburl="jdbc:mysql://localhost:3306/sctu-javaweb-2018?serverTimezone=UTC&characterEncoding=UTF-8";
    private String dbuser="root";
    private String dbpassword="123456";
    private boolean status=false;
    private int count;
    public boolean Login(String username, String password)throws Exception{
         Connection connection=null;
         PreparedStatement preparedStatement=null;
         ResultSet resultSet=null;

         Class.forName(dbdriver);
         connection= DriverManager.getConnection(dburl,dbuser,dbpassword);

         String sql="select * from user_information  WHERE username=? and password=?";
        preparedStatement=connection.prepareStatement(sql);
         preparedStatement.setString(1,username);
         preparedStatement.setString(2,password);
         resultSet=preparedStatement.executeQuery();
         while (resultSet.next()){
          count=resultSet.getInt(1);
         }
        System.out.println(count);
         if (count>0){
             status=true;
         }

         else {
             status=false;

         }

         return status;
     }
}
